unit uGraph;

interface

uses Graphics;

type
  TGraph = class
  private
    FSurface: TBitmap;
    FCanvas: TCanvas;
    procedure SetSurface(const Value: TBitmap);
    procedure SetCanvas(const Value: TCanvas);
  public
    constructor Create(ACanvas: TCanvas; AWidth, AHeight: Integer);
    destructor Destroy; override;
    property Surface: TBitmap read FSurface write SetSurface;
    property Canvas: TCanvas read FCanvas write SetCanvas;
    function Width: Integer;
    function Height: Integer;
    procedure Render;
    procedure Clear;
  end;

var
  Graph: TGraph;

implementation

uses Windows, Types, uUtils;

{ TGraph }

procedure TGraph.Clear;
begin
  Surface.Canvas.Brush.Color := 0;
  Surface.Canvas.FillRect(Rect(0, 0, Surface.Width, Surface.Height));
end;

constructor TGraph.Create(ACanvas: TCanvas; AWidth, AHeight: Integer);
begin
  Canvas := ACanvas;
  Surface := Graphics.TBitmap.Create();
  Surface.Width := AWidth;
  Surface.Height := AHeight;
  Surface.Canvas.Brush.Style := bsClear;
  Surface.Canvas.Font.Name := 'Tahoma';
  Surface.Canvas.Font.Size := 11;
  Surface.PixelFormat := pf16bit;	 
  ScreenWidth := (AWidth div TileSize) - PanelWidth;
  ScreenHeight := AHeight div TileSize;
  end;

destructor TGraph.Destroy;
begin
  Surface.Free;
  inherited;
end;

function TGraph.Height: Integer;
begin
  Result := Surface.Height;
end;

procedure TGraph.Render;
begin
  Canvas.Draw(0, 0, Surface);
end;

procedure TGraph.SetCanvas(const Value: TCanvas);
begin
  FCanvas := Value;
end;

procedure TGraph.SetSurface(const Value: Graphics.TBitmap);
begin
  FSurface := Value;
end;

function TGraph.Width: Integer;
begin
  Result := Surface.Width;
end;

end.
